package com.chixing.ih.module.system.mapper;

import com.chixing.ih.common.IhRepository;
import com.chixing.ih.module.system.mapper.provider.UserMapperProvider;
import com.chixing.ih.module.system.pojo.User;
import com.chixing.ih.module.system.pojo.dto.UserRegisterDTO;
import org.apache.ibatis.annotations.*;

/**
 * @author 刘岩
 * @version 1.0
 * @Desc Practice makes perfect
 * @date 2020/9/21 22:16
 */
@Mapper
public interface UserMapper extends IhRepository<User> {

    /**
     * 用户注册
     *
     * @param userRegisterDTO
     * @return
     */

    @InsertProvider(type = UserMapperProvider.class, method = "insertOne")
    @Options(useGeneratedKeys = true, keyProperty = "userId", keyColumn = "user_id")
    int insertUser(UserRegisterDTO userRegisterDTO);

    /**
     * 根据账户判断用户是否已经注册和用户名是否存在以及密码是否正确
     *
     * @param userAccount
     * @return
     */

    @SelectProvider(type = UserMapperProvider.class, method = "getOneByAccount")
    @Results(id = "userMap", value = {
            @Result(id = true, column = "user_id", property = "userId"),
            @Result(column = "user_account", property = "userAccount"),
            @Result(column = "nick_name", property = "nickName"),
            @Result(column = "user_password", property = "userPassword"),
            @Result(column = "user_telephone", property = "userTelephone"),
            @Result(column = "user_status", property = "userStatus"),
            @Result(column = "user_career", property = "userCareer"),
            @Result(column = "user_career_direct", property = "userCareerDirect"),
            @Result(column = "user_position", property = "userPosition"),
            @Result(column = "user_company", property = "userCompany"),
            @Result(column = "user_email", property = "userEmail"),
            @Result(column = "support_num", property = "supportNum"),
            @Result(column = "alipay_account", property = "alipayAccount"),
            @Result(column = "wechat_account", property = "wechatAccount"),
            @Result(column = "qq_account", property = "qqAccount"),
            @Result(column = "role_id", property = "roleId"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "is_deleted", property = "isDeleted")

    })
    User getUserByAccount(String userAccount);

    /**
     * 根据用户昵称判断用户昵称是否重复
     *
     * @param userNickName
     * @return
     */
    @SelectProvider(type = UserMapperProvider.class, method = "getOneByNickName")
    @ResultMap("userMap")
    User getUserByNickName(String userNickName);


    /**
     * 判断用户账号密码是否正确
     *
     * @param user
     * @return
     */

    @SelectProvider(type = UserMapperProvider.class, method = "getOne")
    @Results(id = "userPasswordMap", value = {
            @Result(id = true, column = "user_id", property = "userId"),
            @Result(column = "user_account", property = "userAccount"),
            @Result(column = "nick_name", property = "nickName"),
            @Result(column = "user_telephone", property = "userTelephone"),
            @Result(column = "user_status", property = "userStatus"),
            @Result(column = "user_career", property = "userCareer"),
            @Result(column = "user_career_direct", property = "userCareerDirect"),
            @Result(column = "user_position", property = "userPosition"),
            @Result(column = "user_company", property = "userCompany"),
            @Result(column = "user_email", property = "userEmail"),
            @Result(column = "support_num", property = "supportNum"),
            @Result(column = "alipay_account", property = "alipayAccount"),
            @Result(column = "wechat_account", property = "wechatAccount"),
            @Result(column = "qq_account", property = "qqAccount"),
            @Result(column = "role_id", property = "roleId"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "is_deleted", property = "isDeleted")

    })
    User getUser(User user);


}
